package mao.serializable;

import java.io.*;

/**
 * @author Totoro
 * @date 2020/7/13
 * @explain:同一对象序列化多次，实际只存储对应的ID
 */
public class person implements Serializable  {

    private String name;
    private Integer age;

    public static void main(String[] args) throws Exception{
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("object.txt"));
        person mao = new person("mao", 25);
        oos.writeObject(mao);
        oos.writeObject(mao);

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("object.txt"));
        person o1 = (person)ois.readObject();
        person o2 = (person)ois.readObject();
        System.out.println(o1 == o2);
        System.out.println(o1 == mao);
        System.out.println(o2 == mao);
        //Object o2 = ois.readObject();
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}
